package com.recharge.api.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class PartyUtil {


    public static String sendRequest(String apiUrl, String requestMessage) throws IOException {
        URL url = new URL(apiUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod(requestMessage);  // POST request | 设置为 POST or GET
        connection.setDoOutput(true);

        // You can send body data here if needed
        try (OutputStream os = connection.getOutputStream()) {
            os.write("".getBytes());  // No body data needed
        }

        // Read and print response | 读取并打印响应
        try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
            String inputLine;
            StringBuilder response = new StringBuilder();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            return response.toString();
        }
    }

}
